<?php
declare (strict_types=1);

namespace app\command;

use app\common\Redis;
use app\model\Marker;
use app\model\User;
use app\service\MarkerService;
use app\service\MiniappService;
use app\service\TencentMapService;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\helper\Arr;

class Test extends Command
{

    protected function configure()
    {
        // 指令配置
        $this->setName('test')
            ->setDescription('the test command');
    }

    protected function execute(Input $input, Output $output)
    {
        $user =User::where(['id' => 2])->find();
        var_dump(Arr::get($user, 'avatar_upload.url', Arr::get($user, 'avatar')));
//        $markerService = new MarkerService();
//        $markerService->syncRedisCoords();
//        $markerService->getWalkingByCategory(12, 2);
        // 指令输出
//        $this->getBeside(1);
//        [$qr, $result] = MiniappService::getUnlimitQr('2');
//        if (!$qr) {
//            var_dump($result);
//        }
//        file_put_contents('marker2.png', $result);
//        $markerService->saveQr(1, $result);

        $list = Marker::query()->field(['id'])->select();
        foreach ($list as $model) {
            [$isOk, $qrCode] = MiniappService::getUnlimitQr((string)$model->id);
            if (!$isOk) {
                $output->writeln($qrCode);
            }
            // 保存小程序二维码
            [$isOk, $saveRes] = (new MarkerService())->saveQr($qrCode, 0);
            if (!$isOk) {
                $output->writeln($saveRes);
            }
            Marker::update(['qrcode_id' => $saveRes], ['id' => $model->id]);
            sleep(1);
        }
    }
}
